<script type="text/javascript" >
    jQuery(document).ready(function(){
        jQuery('.stExtra').remove();
    });
    stFacebookToolbox.load_tooltip();
    stFacebookToolboxcustom.on_submitform_new('#template_upload');
    stFacebookToolbox.loadUploadButton('200');
    stFacebookToolbox.loadRemoveButton();
    stFacebookToolbox.shortAction();
    stFacebookToolbox.sortColumn();
        jQuery("a[rel^='prettyPhoto']").prettyPhoto({
            theme:'facebook',
            default_height:100,
            keyboard_shortcuts: false
        });
    function add_image(){
        jQuery('.upload_field').slideDown();
        jQuery("#id").val('');
        jQuery("#name").val('');
        jQuery("#calculation").val('');
        
    }
    function edit(id,name,calculation){
        jQuery('.upload_field').slideDown();
        jQuery("#id").val(id);
        jQuery("#name").val(name);
        jQuery("#calculation").val(calculation);
    }
</script>
<style>
    th.column-DiscountTypeID{
        width:40px;
    }
</style>

<div class="w100p bgl">
    <div class="w100p bgr p5b">
        <ul class="postcardAction" style="margin-left: 10px;padding-top: 15px;">
                <li>
                    <a class="button add-new-h2 anchor" onclick="add_image();">
                        Add new discount type
                    </a>
                </li>
            </ul>
        <div class="upload_field" style="<?php echo $display;?>padding-left:13px;">
                <form method="post" action="<?php echo admin_url('/admin.php?page=' . $config['plugin_name'] . '&action=' . $current_action) ?>" style="display: block;" id="template_upload" class="stform">
                    <ul>
                        <li>
                            <label>Name:</label>
                            <div class="required">
                                <input type="text" name="data[name]" id="name" class="required" />
                                <input type="hidden" name="data[id]" id="id"  />
                            </div>
                            <br clear="all">
                        </li>
                        <li>
                            <label>Calculation:</label>
                            <div class="required">
                                <input type="text" name="data[calculation]" id="calculation" class="required" />

                            </div>
                            <br clear="all">
                        </li>
                        
                        <li>
                            <input type="submit" value="Submit">
                            <input type="button" onclick="jQuery('.upload_field').slideUp()" value="Close">
                        </li>
                    </ul>
                    <br style="clear:both;" />
                </form>
            </div>
<table class="widefat" cellspacing="0">
                <thead>
                    <tr>
                        <?php print_column_headers('stFacebookToolbox_stFacebookToolbox'); ?>
                    </tr>
                </thead>

                <tbody>
                <?php
                if (count($results) > 0) {
                    
                    $tr_class = "";
                    $upload_data = wp_upload_dir();
                    foreach ($results as $result) {
                        if( empty($tr_class) || $tr_class == "class='bg_gray2'"){
                            $tr_class = "class='bg_gray1'";
                        }else{
                            $tr_class = "class='bg_gray2'";
                        }
                        echo "<tr id='$result->DiscountTypeID' $tr_class >"
                        . "<td>" . $result->DiscountTypeID
                        . "<div class=\"row-actions short_action\">"
                        . "<div onclick='edit($result->DiscountTypeID,\"$result->DiscountTypeName\",\"$result->DiscountTypeCalculation\");' style='cursor:pointer;'>Edit | </div>"
                        . "<span class='trash' short_action='delete' id='$result->DiscountTypeID' confirm='Are you sure you want to delete this discount type?' style='cursor:pointer;'>Trash </span>"
                        . "</div>"
                        . "</td>"
                        . "<td>" . $result->DiscountTypeName
                        
                        . "</td>"
                        . "<td>{$result->DiscountTypeCalculation}"
                        . "</td>"
                          . "</td>"
                        . "</td>"
                        
                        . "</tr>"
                        ;
                    }
                }
                ?>
                </tbody>
            </table>
            <div class="page_d">
                <?php echo $pagination?>
                <div class="cl"></div>
            </div>
    </div>
</div>